# -*- coding: utf-8 -*-
"""
Created on Wed Mar 17 15:01:13 2021

@author: hp
"""

import pandas as pd;
import numpy as np;

input_data = "D:/PythonWord/3/Apriori/data/work1.xlsx";
output_data = "D:/PythonWord/3/Apriori/data/work1_an.xlsx";

data = pd.read_excel(input_data, header = 0 , index_col = 0);
#print(data);
c = list(data.columns);
#print(c);
support_min = 0.2;
conf_min = 0.5;
R = pd.DataFrame(columns=[10,20,30])
for q in range(len(c)):
    for h in range(len(c)):
        if c[q]!=c[h]:
            support_num=((data[c[q]]==1)&(data[c[h]]==1)).sum()#支持数
            support=support_num/len(data)#支持度
            if support>=support_min: #支持度大于等于最小支持度
                conf=support_num/(data[c[q]].sum())#置信度
                if  conf>=conf_min:#置信度大于等于最小置信度的规则
                    s=pd.Series([c[q]+c[h],support,conf],index=[10,20,30])
                    R=R.append(s,ignore_index=True)
print(R);